package cn.weiyan.seatademo.bank2.server.impl;

import cn.weiyan.seatademo.bank2.dao.AccountInfoDao;
import cn.weiyan.seatademo.bank2.server.AccountInfoServer;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author misterWei
 * @create 2020年02月14号:17点41分
 * @mailbox mynameisweiyan@gmail.com
 */
@Service
@Slf4j
public class AccountInfoServerImpl implements AccountInfoServer {

    @Autowired
    private AccountInfoDao accountInfoDao;


     //本地事务注解
    @Transactional
    @Override
    public void updateAccountBalance(String accountNo, Double amount) {
       //张三账户  减去金额,把该金额添加到李四账户中

            accountInfoDao.updateAccountBalance("2",amount);

   log.error(RootContext.getXID());
        if (amount == 3) {
            throw new RuntimeException("exception...");
        }


    }
}
